<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	Object obj = request.getSession().getAttribute("role_resource");
	if (null == obj) {
		response.setStatus(1000);
		return;
	}
%>

<script type="text/javascript">
	function img_path() {
	}

	//拼装路径
	var upload = function() {
		var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
		var path = node.getPath();//获取当前选中树节点的路径
		var type = Ext.getCmp("template.type").getValue();//模板类型
		if ("1" == type)
			type = "TNO";
		else if ("2" == type)
			type = "HTML";
		var version = Ext.getCmp("template.version").getValue();//版本
		var list = path.split("/");
		var wdfpath;
		wdfpath = list[2] + "/WFD/" + type + "/" + list[list.length - 1] + "/"
				+ version;
		return wdfpath;
	};

	var Temp = {
		uploadError:function(msg) {
			Ext.Msg.alert("Message", msg);
		},
		begin:function(){
			//上传开始
			Ext.MessageBox.wait("上传进度","上传中，请等待。。。");
		},
		imgUploadcomp : function(d) {
			//上传结束
			Ext.MessageBox.updateProgress(1);
            Ext.MessageBox.hide();
			var a = d.split("|");
			if (a[0] == "success" || a[0] == "exists") {
				var i = image_store.find("path", a[1], 0, true,true);//匹配store中的路径,已有不在新增
				if (i == -1) {
					var val = new image_record({
						"path" : a[1]
					});
					image_store.add(val);
				}
			}
			var msg = "";
			if (a[0] == "success") {
				msg = "样张上传成功!";
			} else if (a[0] == "exists") {
				msg = "样张已存在,请勿重复上载!";
			}
			Ext.Msg.alert("提示", msg);
		},
		wfdUploadcomp : function(d) {
			//上传结束
			Ext.MessageBox.updateProgress(1);
            Ext.MessageBox.hide();
			var a = d.split("|");
			if (a[0] == "exists" || a[0] == "success") {
				Ext.getCmp("template.storpath").setValue(a[1]);
			}
			var msg = "";
			if (a[0] == "success") {
				msg = "模板文件上传成功!";
			} else if (a[0] == "exists") {
				msg = "模板文件已存在,请勿重复上载!";
			}
			Ext.Msg.alert("提示", msg);
		},
		jobUploadcomp : function(d) {
			//上传结束
			Ext.MessageBox.updateProgress(1);
            Ext.MessageBox.hide();
			var a = d.split("|");
			if (a[0] == "exists" || a[0] == "success") {
				Ext.getCmp("template.jobpath").setValue(a[1]);
			}
			var msg = "";
			if (a[0] == "success") {
				msg = "JOB文件上传成功!";
			} else if (a[0] == "exists") {
				msg = "JOB文件已存在,请勿重复上载!";
			}
			Ext.Msg.alert("提示", msg);
		},
		//样张点击前验证
		imgUploadPath : function() {
			getFlashObject("imgs").addID(upload());
			return true;
		},
		//模板文件点击前验证,只有草稿状态能上传
		wfdUploadPath : function() {
			var state = Ext.getCmp("template.state").getValue();
			if (state != "2") {
				//Ext.Msg.alert("提示", "此状态下禁止上传模板文件!");
				Ext.Msg.show({
		   			title:"警告",
		  			 msg: "此状态下禁止上传模板文件!",
		   			buttons: Ext.Msg.OK,
		   			animEl: "elId",
		   			icon:Ext.MessageBox.WARNING
					});
				return false;
			}
			getFlashObject("wfd").addID(upload());
			return true;
		},
		//job文件点击前验证,只有草稿状态能上传	
		jobUploadPath : function() {
			var state = Ext.getCmp("template.state").getValue();
			if (state != "2") {
				//Ext.Msg.alert("提示", "此状态下禁止上传JOB文件!");
				Ext.Msg.show({
		   			title:"警告",
		  			msg: "此状态下禁止上传JOB文件!",
		   			buttons: Ext.Msg.OK,
		   			animEl: "elId",
		   			icon:Ext.MessageBox.WARNING
					});
				return false;
			}
			getFlashObject("job").addID(upload());
			return true;
		}
	};

	//模板状态下拉列表
	var state_store = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "0",
			text : "退回"
		}, {
			id : "1",
			text : "启用"
		}, {
			id : "2",
			text : "草稿"
		} ]
	});
	//模板状态下拉列表
	var state_store1 = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "",
			text : "全部"
		}, {
			id : "0",
			text : "退回"
		}, {
			id : "1",
			text : "启用"
		}, {
			id : "2",
			text : "草稿"
		} ]
	});
	//账单类型下拉列表
	var type_store = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "1",
			text : "纸质"
		}, {
			id : "2",
			text : "电子"
		} ]
	});
	var type_store1 = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "",
			text : "全部"
		},{
			id : "1",
			text : "纸质"
		}, {
			id : "2",
			text : "电子"
		} ]
	});

	//卡产品树数据源
	var tree_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "id", "text", "leaf" ],
		url : "product!ProdType.action"
	});
	//模板列表数据源
	var data_store = new Ext.data.JsonStore({
		root : "data",
		totalProperty : "total",
		fields : [ "id", "name", "version", "cardid", "cardname", "type",
				"storpath", "jobpath", "images", "state", "personid",
				"createtime", "images" ],
		url : "template!NotVerifyList.action"
	});
	//模板从表数据源
	var sub_store = new Ext.data.JsonStore({
		root : "data",
		totalProperty : "total",
		fields : [ "stencil_no", "version", "in_no", "in_name" ],
		url : "template!listTemplateSub.action"
	});
	//模板版本号数据源
	var version_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "version" ],
		url : "template!selectVersion.action"
	});
	//模板id数据源
	var tempid_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "id" ],
		url : "template!DoTempid.action"
	});
	//编辑框record	
	var sub_record = Ext.data.Record.create([ "in_no", "in_name" ]);
	//图片路径,上传
	var image_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "path" ],
		url : "template!queryImage.action"
	});
	//样张框 record
	var image_record = Ext.data.Record.create([ "path" ]);
	//样张路径
	var img_path = function(e) {
		var record = Ext.getCmp("edit_grid").getSelectionModel().getSelected();
		if (record) {
			sub_store.remove(record);
			//Ext.Msg.alert("提示", "操作成功!");
			Ext.Msg.show({
		   		title:"提示",
		   		msg:"操作成功!",
		   		buttons:Ext.Msg.OK,
		   		icon: Ext.MessageBox.INFO
				});
		} else {
			//Ext.Msg.alert("错误", "未选中任何行信息,无法执行此操作!");
			Ext.Msg.show({
		   			title:"警告",
		  			msg: "未选中任何行信息,无法执行此操作!",
		   			buttons: Ext.Msg.OK,
		   			animEl: "elId",
		   			icon:Ext.MessageBox.WARNING
					});
			return;
		}
	};

	//ajax
	var oper = function(url, params, parent, panel) {
		Ext.Ajax.request({
			clientValidation : true,
			params : params,
			url : url,
			success : function(response, opts) {
				var d = eval("(" + response.responseText + ")");
				if (d.code == "1") {
					Ext.getCmp("review").doRefresh();//刷新页面
					//Ext.Msg.alert("成功", d.data);
					Ext.Msg.show({
		   				title:"提示",
		   				msg:"操作成功!",
		   				buttons:Ext.Msg.OK,
		   				icon: Ext.MessageBox.INFO
						});
					Ext.getCmp("save").setDisabled(false);
					if (panel != null) {
						
						panel.layout.setActiveItem(0);
					}
				} else {
					//Ext.Msg.alert("失败", d.data);
					Ext.Msg.show({
		   				title:"提示",
		   				msg:"操作失败!",
		   				buttons:Ext.Msg.OK,
		   				icon: Ext.MessageBox.ERROR
						});
				}
				Ext.getCmp("verify").setDisabled(false);
			},
			failure : function(response, opts) {
			}
		});
	};

	//定义数据显示面板
	var p1 = {
		id : "p1",
		xtype: "grid",
		stripeRows:true,
		loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
		autoExpandColumn:"storpath",//自动填充
		autoExpandMin : 100,//自动填充最小宽度
		store : data_store,
		headersDisabled: true,
		sm : new Ext.grid.RowSelectionModel({//行选择监听,判断状态是否可审核
			listeners : {
				"rowselect" : function(s, index) {
					var state = data_store.getAt(index).data.state;
					if (state === "1") {//启用不能修改,不能审核
						Ext.getCmp("verify").setDisabled(true);
						Ext.getCmp("edit_tem").setDisabled(true);
					} else {
						Ext.getCmp("verify").setDisabled(false);
						Ext.getCmp("edit_tem").setDisabled(false);
					}
					/*
					if (state === "2") {//只有草稿能上传模板,job文件
						Ext.getCmp("wfd").setDisabled(false);
						Ext.getCmp("job").setDisabled(false);
					} else {
						Ext.getCmp("wfd").setDisabled(true);
						Ext.getCmp("job").setDisabled(true);
					}
					*/
				}
			}
		}),
		columns : [ new Ext.grid.RowNumberer({
			header : "序号",
			width : 35, 
			menuDisabled: true
		}), {
			header : "模板编号",
			dataIndex : "id", 
			menuDisabled: true
		}, {
			header : "名称",
			dataIndex : "name", 
			menuDisabled: true
		}, {
			header : "版本",
			dataIndex : "version", 
			menuDisabled: true
		}, {
			header : "卡产品",
			dataIndex : "cardname", 
			menuDisabled: true
		}, {
			header : "类型",
			dataIndex : "type", 
			menuDisabled: true,
			renderer : function(input) {
				if ("1" == input)
					return "纸质";
				else if ("2" == input)
					return "电子";
			}
		}, {
			header : "存储路径",
			dataIndex : "storpath",
			id : "storpath", 
			menuDisabled: true
		}, {
			header : "状态",
			dataIndex : "state", 
			menuDisabled: true,
			renderer : function(input) {
				if ("0" == input)
					return "退回";
				else if ("1" == input)
					return "启用";
				else if ("2" == input)
					return "草稿";
				else if ("3" == input)
					return "审核中";
			}
		}, {
			header : "创建人",
			dataIndex : "personid", 
			menuDisabled: true
		}, {
			header : "创建时间",
			dataIndex : "createtime", 
			menuDisabled: true
		} ],
		buttonAlign : "center",
		bbar : new Ext.ux.PagingToolbar({
			id : "review",
			pageSize : limit,
			store : data_store
		}),
		buttons : [
				{
					text : "新增",
					handler : function() {
						var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
						if (node && node.isLeaf()) {
								oper_type = "add";
								Ext.getCmp("p2").resetParam(node.id, node.text);
								sub_store.removeAll();
								image_store.removeAll();
								Ext.getCmp("templ_panel").layout.setActiveItem(1);
						} else {
							//Ext.Msg.alert("错误", "未选中任何卡产品,无法进行此操作!");
							Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何卡产品,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
						}
					}
				},
				{
					text : "修改",
					id : "edit_tem",
					handler : function() {
						var p1 = this.ownerCt.ownerCt;
						var panel = p1.ownerCt;
						var record = Ext.getCmp("p1").getSelectionModel().getSelected();
						if (record) {
							Ext.getCmp("p2").setParam(record.data);
							oper_type = "upd";
							sub_store.load({
								params : {
									"templateSub.stencil_no" : record.data.id
								}
							});
							image_store.load({
								params : {
									"template.id" : record.data.id
								}
							});
							Ext.getCmp("templ_panel").layout.setActiveItem(1);
						} else {
							//Ext.Msg.alert("错误", "未选中任何行信息,无法进行此操作!");
							Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
						}
					}
				},
				{
					text : "进入审核",
					id : "verify",
					handler : function() {
						var p1 = this.ownerCt.ownerCt;
						var panel = p1.ownerCt;
						var record = p1.getSelectionModel().getSelected();
						if (record) {
							var url = "template!updState.action";
							var params = {
								"template.id" : record.data.id,
								"template.name" : record.data.name,
								"template.cardid" : record.data.cardid,
								"template.type" : record.data.type,
								"template.version" : record.data.version,
								"template.state" : "3"
							};
							var params2 = {
								"template.cardid" : record.data.cardid
							};
							oper(url, params, params2, Ext
									.getCmp("templ_panel"));
						} else {
							//Ext.Msg.alert("错误", "未选中任何行信息,无法进行此操作!");
							Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
						}
					}
				} ],
		//查询条件
		tbar : ["&nbsp&nbsp账单类型:",
				{
					xtype : "billCombox",
					width : 80,
					store : type_store1,
					id : "selcbut",
					value: "",
					listeners : {
						"select" : function(comb, rcord, index) {
							var node = Ext.getCmp("tempTree")
									.getSelectionModel().getSelectedNode();
							if (node) {
								if (node.isLeaf()) {
									data_store.baseParams["template.type"] = rcord.data.id;
									data_store.load({
										params : {
											start : 0,
											limit : limit
										}
									});
								}
							} else {
								//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
								Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
							}
						}
					}
				} ,"&nbsp&nbsp状态:",
					  {
						xtype : "billCombox",
						width : 80,
						store : state_store1,
						id : "selcstatebut",
						value: "",
						listeners : {
							"select" : function(comb, rcord, index) {
								var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
								if (node) {
									if (node.isLeaf()) {
										data_store.baseParams["template.state"] = rcord.data.id;
										data_store.load({
											params : {
												start : 0,
												limit : limit
											}
										});
									}
								} else {
									//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
									Ext.Msg.show({
			   							title:"警告",
			   							msg: "未选中任何行信息,无法进行此操作!",
			   							buttons: Ext.Msg.OK,
			   							animEl: "elId",
			   							icon:Ext.MessageBox.WARNING
								});
								}
							}
						}
				},"&nbsp&nbsp模板名称:",
					  {
						xtype : "textfield",
						id : "selcsnamebut",
						enableKeyEvents:true,
						listeners : {
							keypress:function(t,e){
								 if(13==e.getKey()){
									var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
									if (node) {
										if (node.isLeaf()) {
											data_store.baseParams["template.name"] = t.getValue();
											data_store.load({
												params : {
													start : 0,
													limit : limit
												}
											});
										}
									} else {
										//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
										Ext.Msg.show({
				   							title:"警告",
				   							msg: "未选中任何行信息,无法进行此操作!",
				   							buttons: Ext.Msg.OK,
				   							animEl: "elId",
				   							icon:Ext.MessageBox.WARNING
									});
									}
								}
							}
						}
				} ]
	};

	var p4 = {
		xtype : "editorgrid",
		id : "edit_grid",
		enableColumnMove : false,
		enableHdMenu : false,
		title : "数据模块输入信息",		
		autoExpandColumn : "in_name",
		autoExpandMin : 100,
		loadMask : true,
		height : 138,
		selModel : new Ext.grid.RowSelectionModel(),//设置为行选择器
		store : sub_store,
		headersDisabled: true,
		columns : [
				new Ext.grid.RowNumberer({
					header : "序号",
					width : 35
				}),
				{
					dataIndex : "in_no",
					id : "in_no",
					header : "数据模块输入编号", 
					menuDisabled: true,
					editor : new Ext.form.NumberField({
						allowBlank : false,
						maxLength : 1,//最大输入长度
						msgTarget : "under",
						validator : function(val) {
							var inno = sub_store.find("in_no", val, 0, true,
									true);
							var record = Ext.getCmp("edit_grid")
									.getSelectionModel().last;
							if (inno != -1 && inno != record) {
								return "数据模块输入编号需唯一!";
							}
							return true;
						}
					})
				}, {
					dataIndex : "in_name",
					id:"in_name",
					header : "数据模块输入名称", 
					menuDisabled: true,
					editor : new Ext.form.TextField({
						allowBlank : false,
						maxLength : 50,//最大输入长度
						msgTarget : "under"
					})
				}],
		
		tbar : [
				"->",
				{
					text: "添加从表信息",
					handler : function() {
						var val = new sub_record({
							"in_no" : "",
							"in_name" : ""
						});
						sub_store.add(val);
					}
				},
				{
					text: "删除从表信息",
					handler : function() {
						var record = Ext.getCmp("edit_grid")
								.getSelectionModel().getSelected();
						if (!record) {
							Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
							return;
						}
						sub_store.remove(record);
						Ext.Msg.show({
		   					title:"提示",
		   					msg:"操作成功!",
		   					buttons:Ext.Msg.OK,
		   					icon: Ext.MessageBox.INFO
							});
					}
				}]				
	};

	//上传个性化区域
	var p5 = {
		xtype : "grid",
		columnWidth : 1,
		enableColumnMove : false,
		enableHdMenu : false,
		title : "样张提示图",
		loadMask : true,
		height : 114,
		autoExpandColumn : "path",
		autoExpandMin : 100,
		selModel : new Ext.grid.RowSelectionModel(),//设置为行选择器
		store : image_store,
		headersDisabled: true,
		columns : [
				new Ext.grid.RowNumberer({
					header : "序号",
					width : 35
				}),
				{
					dataIndex : "path",
					header : "文件名称",
					id : "path", 
					menuDisabled: true
				},
				{
					xtype : "actioncolumn",
					header : "预览",
					width : 34, 
					menuDisabled: true,
					items : [ {
						icon : "images/shared/icons/fam/information.png", // Use a URL in the icon config
						tooltip : "预览",
						handler : function(grid, rowIndex, colIndex) {
							var rec = image_store.getAt(rowIndex);
							var win=Ext.getCmp("showimages");
							win.show();
							var html="<img id='imgpage' width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(rec.get('path'))+"'/>";
							win.update(html);
						}
					} ]
				}, {
					xtype : "actioncolumn",
					header : "删除", 
					menuDisabled: true,
					width : 34,
					items : [ {
						icon : "images/shared/icons/fam/delete.gif",// Use a URL in the icon config
						tooltip : "删除",
						handler : function(grid, rowIndex, colIndex) {
							image_store.removeAt(rowIndex);
							//Ext.Msg.alert("提示", "删除成功!");
							Ext.Msg.show({
		   						title:"提示",
		   						msg:"操作成功!",
		   						buttons:Ext.Msg.OK,
		   						icon: Ext.MessageBox.INFO
								});
						}
					} ]
				} ]
	};

	//详细信息
	var p2 = {
		id : "p2",
	    labelWidth: 100,
		xtype: "form",
	    bodyStyle:"padding:5px 5px 0",
		defaultType: "textfield",
		autoScroll : true,
		items : [
				{
					id : "template.id",
					fieldLabel : "模板编号",
					name : "template.id",
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.name",
					fieldLabel : "模板名称",
					name : "template.name",
					allowBlank : false,
					vtype : "alphanumchinese",
					maxLength : 50,//最大输入长度
					anchor : "100%",
					validator : function(val) {
						if (val == "")
							return "该输入项为必输项！";
						if (Ext.fucCheckCHLength(val) > 50) {
							return "请输入50个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
						}
						return true;
					}
				},
				{
					id : "template.version",
					fieldLabel : "版本号",
					name : "template.version",
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.cardid",
					hidden : true,
					name : "template.cardid"
				},
				{
					id : "template.cardname",
					fieldLabel : "卡产品名称",
					name : "template.cardname",
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.type",
					fieldLabel : "账单类型",
					name : "template.type",
					xtype : "billCombox",
					store : type_store,
					listeners : {
						"select" : function() {
							version_store.load({
								params : {
									"template.cardid" : Ext.getCmp(
											"template.cardid").getValue(),
									"template.type" : this.getValue()
								},
								callback : function() {
									Ext.getCmp("template.version").setValue(
											this.getAt(0).data.version);
								}
							});
						}
					}
				}, {
					id : "template.state",
					fieldLabel : "状态",
					name : "template.state",
					xtype : "billCombox",
					store : state_store,
					disabled : true
				}, {
					id : "template.storpath",
					fieldLabel : "模板存储路径",
					name : "template.storpath",
					anchor : "100%",
					allowBlank : false,
					maxLength : 50,//最大输入长度
					msgTarget : "under",
					disabled : true
				}, {
					id : "template.jobpath",
					fieldLabel : "JOB文件存储路径",
					name : "template.jobpath",
					allowBlank : false, //不能为空				            	
					maxLength : 50, //最大输入长度
					msgTarget : "under",
					anchor : "100%",
					disabled : true
				}, p5, p4],
				
		buttonAlign : "center",
		buttons : [
				{
					xtype : "flash",
					id : "imgs",
					anchor : "anchor",
					expressInstall : true,//如果没有安装flash，提示用户进行安装							
					width : 70,
					height : 22,
					url : "flash/upload.swf",
					flashVars : {
						requestUrl : "upload.action",
						type : "template",
						butText : "样张上传",
						fileFilterName : "Images (*.jpg, *.jpeg, *.png )",
						fileFilterValue : "*.jpg;*.jpeg;*.png",
						begin: encodeURI(Temp.begin),
						error : encodeURI(Temp.uploadError),
						complete : encodeURI(Temp.imgUploadcomp),
						validate : encodeURI(Temp.imgUploadPath)
					}
				},
				{
					xtype : "flash",
					anchor : "anchor",
					id : "wfd",
					expressInstall : true,//如果没有安装flash，提示用户进行安装							
					width : 70,
					height : 22,
					url : "flash/upload.swf",
					flashVars : {
						requestUrl : "upload.action",
						type : "template",
						butText : "模板上传",
						fileFilterName : "Template (*.wfd)",
						fileFilterValue : "*.wfd",
						begin: encodeURI(Temp.begin),
						error : encodeURI(Temp.uploadError),
						complete : encodeURI(Temp.wfdUploadcomp),
						validate : encodeURI(Temp.wfdUploadPath)
					}
				},
				{
					xtype : "flash",
					anchor : "anchor",
					expressInstall : true,//如果没有安装flash，提示用户进行安装							
					width : 70,
					id : "job",
					height : 22,
					url : "flash/upload.swf",
					flashVars : {
						requestUrl : "upload.action",
						type : "template",
						butText : "JOB上传",
						fileFilterName : "JOB (*.job)",
						fileFilterValue : "*.job",
						begin: encodeURI(Temp.begin),
						error : encodeURI(Temp.uploadError),
						complete : encodeURI(Temp.jobUploadcomp),
						validate : encodeURI(Temp.jobUploadPath)
					}
				},
				{
					xtype : "flash",
					hidden:true,
					url : "flash/upload.swf"
				},
				{
					text : "保存",
					id:"save",
					handler : function(e) {
						var form = this.ownerCt.ownerCt.getForm();
						var id = Ext.getCmp("template.id").getValue();
						var type = Ext.getCmp("template.type").getValue();
						var str = Ext.getCmp("template.name").getValue().toString();
						var type_flag = "";
						if(2==type){
							type_flag = "电子";
						}else if(1==type){
							type_flag = "纸质";
						}
						if (oper_type == "upd") {
							var name = str.substring(0,str.lastIndexOf("["))+"["+type_flag+"]";
							if(str.substring(0,str.lastIndexOf("["))==""){
								name = str+"["+type_flag+"]";
							}
						}
						if(oper_type == "add"){
							var name = str+"["+type_flag+"]";
						}
						var version = Ext.getCmp("template.version").getValue();
						var cardid = Ext.getCmp("template.cardid").getValue();
						
						var storpath = Ext.getCmp("template.storpath")
								.getValue();
						var jobpath = Ext.getCmp("template.jobpath").getValue();
						//提交验证
						if (name == "") {
							//Ext.Msg.alert("操作失败", "模板名称不能为空!");
							Ext.Msg.show({
		   						title:"警告",
		   						msg: "模板名称不能为空!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
							return;
						}
						if (storpath == "") {
							//Ext.Msg.alert("操作失败", "模板存储路径不能为空!");
							Ext.Msg.show({
		   						title:"警告",
		   						msg: "模板存储路径不能为空!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
							return;
						}
						if (jobpath == "") {
							//Ext.Msg.alert("操作失败", "JOB文件存储路径不能为空!");
							Ext.Msg.show({
		   						title:"警告",
		   						msg: "JOB文件存储路径不能为空!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
							return;
							return;
						}
						if (image_store.getCount() == 0) {
							//Ext.Msg.alert("操作失败", "图样存储路径不能为空!");
							Ext.Msg.show({
		   						title:"警告",
		   						msg: "图样存储路径不能为空!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
							return;
						}
						
						
						var url, params;

						if (oper_type == "add") {
							url = "template!add.action";
						} else if (oper_type == "upd") {
							state = "2";
							url = "template!upd.action";
						}
						var store = sub_store;
						var record;
						var list;

						params = {
							"template.id" : id,
							"template.name" : name,
							"template.version" : version,
							"template.cardid" : cardid,
							"template.type" : type,
							"template.storpath" : storpath,
							"template.jobpath" : jobpath,
							"template.images" : "img"
						};
						//为对象添加list属性
						for ( var i = 0; i < image_store.getCount(); i++) {
							path = image_store.getAt(i).data.path;
							params["listImg[" + i + "].path"] = path;
						}
						;

						//为对象添加list属性
						for ( var i = 0; i < store.getCount(); i++) {
							record = store.getAt(i);
							if (record.data.in_no != 0 && !record.data.in_no) {
								//Ext.Msg.alert("操作失败", "输入编号不能为空!");
								Ext.Msg.show({
		   						title:"警告",
		   						msg: "输入编号不能为空!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
								return;
							}
							if (!record.data.in_name) {
								//Ext.Msg.alert("操作失败", "输入名称不能为空!");
								Ext.Msg.show({
		   						title:"警告",
		   						msg: "输入名称不能为空!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
								return;
							}
							params["listTemplateSub[" + i + "].in_no"] = record.data.in_no;
							params["listTemplateSub[" + i + "].in_name"] = record.data.in_name;
						}
						;
						e.setDisabled(true);
						var params2 = {
							"template.cardid" : cardid
						};
						oper(url, params, params2, form.ownerCt);
					}
				}, {
					text : "取消",
					handler : function() {
						Ext.getCmp("templ_panel").layout.setActiveItem(0);
					}
				} ],
				
		setParam : function(data) {
			Ext.getCmp("template.id").setValue(data.id);
			//Ext.getCmp("template.name").setRawValue(data.name);
			Ext.getCmp("template.name").setValue(data.name);
			Ext.getCmp("template.version").setValue(data.version);
			Ext.getCmp("template.cardid").setValue(data.cardid);
			Ext.getCmp("template.cardname").setValue(data.cardname);
			Ext.getCmp("template.type").setValue(data.type);
			Ext.getCmp("template.type").setDisabled(true);
			Ext.getCmp("template.storpath").setValue(data.storpath);
			Ext.getCmp("template.jobpath").setValue(data.jobpath);
			Ext.getCmp("template.state").setValue(data.state);
		},
		resetParam : function(id, name) {
			var type = Ext.getCmp("selcbut").getValue();//获取类型
			if (!type) {
				type = "1";
			}
			version_store.load({
				params : {
					"template.cardid" : id,
					"template.type" : type
				},
				callback : function() {
					Ext.getCmp("template.version").setValue(
						this.getAt(0).data.version);
				}
			});
			tempid_store.load({
				callback : function() {
					Ext.getCmp("template.id").setValue(this.getAt(0).data.id);
				}
			});

			Ext.getCmp("template.name").setValue("");
			Ext.getCmp("template.cardid").setValue(id);
			Ext.getCmp("template.cardname").setValue(name);
			Ext.getCmp("template.type").setValue(type);
			Ext.getCmp("template.type").setDisabled(false);
			Ext.getCmp("template.storpath").setValue("");
			Ext.getCmp("template.jobpath").setValue("");
			Ext.getCmp("template.state").setValue("2");
		}
	};
		
		var temp_pel = new Ext.Panel({
			border : false, 
			layout: "border",
			items : [ {
				id : "tempTree",
				xtype : "billTreePanel",
				dataUrl : "tree!product.action",
				autoScroll : true,
				root : new Ext.tree.AsyncTreeNode({
					id : "root",
					expanded : true
				}),
				listeners : {
					"click" : function(node) {
						if (node.isLeaf()) {
							Ext.getCmp("selcbut").setValue("");//清空查询条件
							Ext.getCmp("selcstatebut").setValue("");//清空查询条件
							Ext.getCmp("selcsnamebut").setValue("");//清空查询条件
														
							data_store.baseParams = {};
							data_store.baseParams["template.cardid"] = node.id;
							data_store.load({
								params : {
									start : 0,
									limit : limit
								}
							});
							Ext.getCmp("templ_panel").layout.setActiveItem(0);
						}
					}
				}
			}, {
				id : "templ_panel",
				region: "center",
				border : false, 
				layout:"card",
				activeItem:0,//显示第一个容器
				items : [ p1, p2 ]
			} ]
		});
	
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(temp_pel);
	CenterPanel.doLayout();
</script>